home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / DISKOPS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-12  |  4.9 KB  |  236 lines

  1. #include <globals2.h>
  2. #include <osbind.h>
  3. extern int  buffer[];        /* holds the char info for disk loading and saving */
  4.  
  5.  
  6. /* 
  7.   the load and save character routines.
  8.  
  9. */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. /*********************/
  16. loadchar(i)
  17. int i[];
  18. {
  19. long int hold;
  20. int k,fd;
  21.  
  22.  if( (fd = Fopen("char.dat",2)) < 0) printf("Error cant open file\n"); 
  23.  
  24.  Fread(fd,(long)400,i); /* read 400 bytes*/
  25.  
  26.  
  27.   strcpy(user.name,i); 
  28.   strcpy(user.align,&i[15]);
  29.   strcpy(user.class,&(i[30]));
  30.   user.lvl= i[45];
  31.   
  32.  
  33.   create_LW_from_two_words( &user.exp, i[46], i[48] );
  34.  
  35.  
  36.   user.ac = i[51];
  37.  
  38.   create_LW_from_two_words( &user.hp, i[52], i[54] );
  39.  
  40.   user.str =i[56];
  41.   user.inte=i[57];
  42.   user.wis=i[58];
  43.   user.dex=i[59];
  44.   user.con=i[60];
  45.   user.weapon_num=i[61];
  46.   user.armor_num=i[62];
  47.   for(k=0;k<10;k++)
  48.    user.backpack[k]=i[63+k];
  49.   
  50.   strcpy(user.weapon,&(i[73]));
  51.   strcpy(user.armor,&(i[88]));
  52.   strcpy(user.spell,&(i[103]));
  53.  
  54.   create_LW_from_two_words( &user.max_hp, i[118], i[120] );
  55.  
  56.   create_LW_from_two_words( &user.max_sp, i[122], i[124] );
  57.  
  58.  
  59.   user.spell_num=i[126];
  60.  
  61. create_LW_from_two_words( &user.sp, i[127], i[129] );
  62.  
  63. create_LW_from_two_words( &user.gold, i[131], i[133] );
  64.  
  65.   for(k=0;k<25;k++)
  66.    user.user_items[k]=i[135+k];
  67.   for(k=0;k<5;k++)
  68.    user.current_spells_active[k]=i[160+k];
  69.   for(k=0;k<2;k++)
  70.    user.hunger_thurst_status[k]=i[165+k];
  71.  
  72.  
  73.  
  74.  create_LW_from_two_words( &user.bank_balance, i[168], i[170] );
  75.    
  76.  
  77.   user.x_loc=i[173];
  78.   user.y_loc=i[174];
  79.   user.weather=i[175];
  80.  user.count=i[176];
  81.   user.way=i[177];
  82.   user.time=i[178];
  83.   user.loc=i[179];
  84.   user.current_sky=i[180];
  85.   user.current_sound=i[181];
  86.   user.clock=i[182];
  87.   user.am_pm=i[183];
  88.   user.sound=i[184];
  89.   user.count=i[185];
  90.   user.dir=i[186];
  91.  
  92.  Fclose(fd);
  93.  
  94. }
  95.  
  96.  
  97.  
  98. /*********************/
  99. /* ints are 2 bytes
  100.    chars are 1 byte 
  101.    longs are 4 bytes 
  102.  
  103.    ALL strings must be terminated with \0 or NULL!!!
  104.  
  105. */
  106.  
  107. savechar(b)
  108. int b[];
  109. {
  110. int pp,k,fd;
  111.  
  112.  
  113.  
  114.   strcpy(b,user.name);
  115.   strcpy(&b[15],user.align);
  116.   strcpy(&(b[30]),user.class);
  117.   b[45] = user.lvl;
  118.  
  119.   
  120.   extract_LW_into_two_words( user.exp,&(b[46])  , &(b[48]));
  121.     
  122.  
  123.   b[51] = user.ac;
  124.   extract_LW_into_two_words( user.hp , &(b[52]) , &(b[54]) );
  125.  
  126.   b[56]=user.str;
  127.   b[57]=user.inte;
  128.   b[58]=user.wis;
  129.   b[59]=user.dex;
  130.   b[60]=user.con;
  131.   b[61]=user.weapon_num;
  132.   b[62]=user.armor_num;
  133.   for(k=0;k<10;k++)
  134.    b[63+k]=user.backpack[k];
  135.   
  136.   strcpy(&(b[73]),user.weapon);
  137.   strcpy(&(b[88]),user.armor);
  138.   strcpy(&(b[103]),user.spell);
  139.  
  140.   extract_LW_into_two_words( user.max_hp , &(b[118]) , &(b[120]) );
  141.   extract_LW_into_two_words( user.max_sp , &(b[122]) , &(b[124]) );
  142.  
  143.   b[126]=user.spell_num;
  144.  
  145.   
  146.   extract_LW_into_two_words( user.sp , &(b[127]) , &(b[129]) );
  147.  
  148.   extract_LW_into_two_words( user.gold , &(b[131]) , &(b[133]) );
  149.  
  150.  
  151.   for(k=0;k<25;k++)
  152.    b[135+k]=user.user_items[k];
  153.   for(k=0;k<5;k++)
  154.    b[160+k]=user.current_spells_active[k];
  155.   for(k=0;k<2;k++)
  156.    b[165+k]=user.hunger_thurst_status[k];
  157.    
  158. extract_LW_into_two_words( user.bank_balance , &(b[168]) , &(b[170]) );
  159.  
  160.  
  161.   b[173]=x;   /* global x&y coords _ OTHERS*/
  162.   b[174]=y;
  163.   b[175]=weather;
  164.   b[176]=count;
  165.   b[177]=way;
  166.   b[178]=time;
  167.   b[179]=loc;
  168.   b[180]=CURRENT_SKY;
  169.   b[181]=CURRENT_SOUND;
  170.   b[182]=clock;
  171.   b[183]=am_pm;
  172.   b[184]=sound;
  173.   b[185]=count;
  174.   b[186]=dir;
  175.  
  176.  if( (fd = Fopen("char.dat",2)) < 0) printf("Error cant open file\n"); 
  177.  
  178.  Fwrite(fd,(long)400,b); /*write 9 bytes to file */
  179.  
  180.  Fclose(fd);
  181.  
  182.  
  183. }
  184.  
  185. /*************************************************************/
  186.  
  187.  
  188. extract_LW_into_two_words( data , MSW , LSW )
  189. long int data;
  190.      int *MSW,*LSW;
  191.  
  192. /* This procedure will take a longword(data) and break
  193.    it up into 2 words
  194.  
  195.    Input: data --> the long word
  196.   Output: MSW  --> the Most Signifigant Word
  197.           LSw  --> the Least Sig. Word
  198.  
  199.  
  200. */
  201. {
  202.  long int result; 
  203.  
  204.                                    /* Extract MSW */
  205.   result = data & 0xffff0000;
  206.   result = result >> 16;
  207.    *MSW = result;                        /* store it in an int */
  208.  
  209.  result = data & 0x0000ffff;          /* extract LSW */
  210.  *LSW = result;                          /*store it */
  211.   
  212.  
  213.  }
  214.  
  215. /**********************************************************/
  216.  
  217. create_LW_from_two_words( result, MSW, LSW )
  218. /* Creates a long word from two words */
  219. long int *result;
  220.      int MSW,LSW;
  221. {
  222.  long int lower_word;
  223.                                  /* This code will form a long int
  224.                                    from 2 ints */
  225.  *result = MSW;                        /* get MSW */
  226.  *result = *result << 16;                 /* put into upper word */
  227.  lower_word = LSW;                          /* get LSW */
  228.  lower_word = lower_word & 0x0000ffff;          /* it gets sign extended, so mask
  229.                                        out upper word */
  230.  
  231.  *result +=lower_word;                       /* add to get final result */
  232.  
  233.  
  234.  
  235. }
  236.